<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="24">
			<p-form-item label="序号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'no', validatorRules.no]" placeholder="请输入序号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="明细" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'detail', validatorRules.detail]" placeholder="请输入明细"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'sn', validatorRules.sn]" placeholder="请输入SN"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'productCode', validatorRules.productCode]" placeholder="请输入产品编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'productName', validatorRules.productName]" placeholder="请输入产品名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品小类" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'subcategory', validatorRules.subcategory]" placeholder="请输入产品小类"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品大类" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mcategory', validatorRules.mcategory]" placeholder="请输入产品大类"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="检验结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'verifyResult', validatorRules.verifyResult]" placeholder="请输入检验结果"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'photoUrl', validatorRules.photoUrl]" placeholder="请输入图片"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="出厂检验操作id" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mesDeliveryInspectOperateId', validatorRules.mesDeliveryInspectOperateId]" placeholder="请输入出厂检验操作id"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'

  export default {
    name: "MesQcDeliInspectItemModal",
	mixins: [SubmitOnchangMixin],
    components: {
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        no: {},
        detail: {},
        sn: {},
        productCode: {},
        productName: {},
        subcategory: {},
        mcategory: {},
        verifyResult: {},
        photoUrl: {},
        mesDeliveryInspectOperateId: {},
        },
        url: {
          add: '/mes-quality/mesQcDeliveryInspectTask/addMesQcDeliInspectItem',
          edit: '/mes-quality/mesQcDeliveryInspectTask/editMesQcDeliInspectItem',
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','no','detail','sn','productCode','productName','subcategory','mcategory','verifyResult','photoUrl','mesDeliveryInspectOperateId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
                  formData['mesDeliveryInspectOperateId'] = this.mainId
                  this.formData['mesDeliveryInspectOperateId'] = this.mainId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','no','detail','sn','productCode','productName','subcategory','mcategory','verifyResult','photoUrl','mesDeliveryInspectOperateId'))
      },


    }
  }
</script>
